var tid = localStorage.getItem("tid");
if(tid!=null)
{
	localStorage.removeItem("tid");
}

var part1 = ID('item1');
var part2 = ID('item2');

function ID(id)
{
	return document.getElementById(id);
}

function m20301Init()
{
	mui.ajax(ASYURI+'M20301.do',{
		data:{
			'tid':tid,
		},
		dataType:'json',
		type:'post',
		timeout:10000,
		success:function(data){
			if(data.tag=='1')
			mui.alert('查询人员出错','提示','确认',function (e) { mui.back(); },'div');
			else if(data.tag=='0')
			{
				var mem = data[1];
				var pre = data[2];
				org("one",mem);
				org("two",pre);
			}
		},
		error:function(xhr,type,errorThrown){ }
	});
}
function org(type,data)
{
	var ul = document.createElement("ul");
	ul.setAttribute("class","mui-table-view");
	
	var slen = data.length;
	for(mi=0;mi<slen;mi++)
	{
		var sd = data[mi];
		var li = document.createElement("li");
		li.setAttribute("class","mui-table-view-cell");

		li.innerHTML = sd.B1012;
		var btn = document.createElement("button");
		btn.setAttribute("type","button");
		btn.setAttribute("class","mui-btn mui-btn-blue");
		btn.setAttribute("onclick","operate('"+type+"','"+sd.B1010+"')")
		btn.innerHTML = "查看用户";
		btn.setAttribute("id",'b'+sd.B1010);
		li.appendChild(btn);
		ul.appendChild(li);
	}
	
	if(type=='one')
	part1.appendChild(ul);
	else
	part2.appendChild(ul);
}

function operate(type,id)
{
	mui.ajax(ASYURI+'B1011.do',{
		data:{'type':"info", 'uid':id,},
		dataType:'json',
		type:'post',
		timeout:10000,
		success:function(data){
			if(data.tag=='0'){
				if(type=='one')
					mui.confirm(data.id,'用户信息',['确认','踢出此用户'],function (e) {
						if(e.index==1)
						{
							var btn = ID('b'+id);
							btn.innerHTML="已踢出";
							btn.setAttribute("disabled","disabled");
							m20301du(id);
						}
					},'div');
				else
					mui.confirm(data.id,'用户信息',['暂时不决定','拒绝请求','同意请求'],function (e) {
						if(e.index==1||e.index==2)
						{
							var status;
							if(e.index==1) status = 2;
							else status = 1;
							var adata = { 'uid':id,'status':status,'tid':tid,'type':'opea'};
							mui.ajax(ASYURI+'B1011.do',{
								data:adata,
								dataType:'json',
								type:'post',
								timeout:10000,
								success:function(data){
									console.log("b"+id);
									if(data.tag=='0'){
										var btn = ID("b"+id);
										btn.setAttribute("disabled","disabled");
										btn.innerHTML="已处理";
										mui.alert('操作成功','提示','确认',function (e) { },'div');
									}
									else
									mui.alert('发生未知错误，操作失败','提示','确认',function (e) {},'div');
								},
								error:function(xhr,type,errorThrown){ }
							});
						}
					},'div')
			}
				
			else
				mui.alert('发生未知错误','提示','确认',function (e) { },'div');
		},
		error:function(xhr,type,errorThrown){  }
	});

}

function m20301du(id)
{
	var udata = {'uid':id,'type':'noInfo','tid':tid,'status':'2'};
	mui.confirm('请问确认踢出此用户吗？','警告',['取消','确认'],function (e) {
		mui.ajax(ASYURI+'B1011.do',{
			data:udata,
			dataType:'json',
			type:'post',
			timeout:10000,
			success:function(data){
				if(data.tag=='0')
				mui.alert('提出该用户成功','提示','确认',function (e) { },'div');
				else
				mui.alert('发生未知错误，踢出失败','提示','确认',function (e) {},'div');
			},
			error:function(xhr,type,errorThrown){ }
		});
	},'div')
}


m20301Init();